package com.xlhj.thymeleaf.controller;

import com.xlhj.thymeleaf.entity.SysUser;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: lcj
 * @Date: 2020/11/9 11:49
 * @Description: Thymeleaf控制器
 * @Version: 0.0.1
 */
@Controller
public class UserController {

    @GetMapping("/users")
    public ModelAndView selectUser() {
        List<SysUser> users = new ArrayList<>();
        SysUser user1 = new SysUser();
        user1.setId(1L);
        user1.setUserCode("admin");
        user1.setUserName("超级管理员");
        user1.setAge((byte) 18);
        user1.setSex((byte) 1);
        user1.setCreateTime(LocalDateTime.now());
        user1.setUpdateTime(LocalDateTime.now());
        users.add(user1);
        SysUser user2 = new SysUser();
        user2.setId(2L);
        user2.setUserCode("test");
        user2.setUserName("测试用户");
        user2.setAge((byte) 20);
        user2.setSex((byte) 2);
        user2.setCreateTime(LocalDateTime.now());
        user2.setUpdateTime(LocalDateTime.now());
        users.add(user2);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("users", users);
        modelAndView.setViewName("users");
        return modelAndView;
    }
}
